package pl.koziolekweb.translator.engine.googleimpl;

import pl.koziolekweb.translator.engine.Language;

/**
 * Defines language information for the Google Translate API.
 * 
 */
public enum GoogleLanguage implements Language {

	/**
	 * 
	 */
	AUTO_DETECT(""),
	/**
	 * 
	 */
	ARABIC("ar"),
	/**
	 * 
	 */
	BULGARIAN("bg"),
	/**
	 * 
	 */
	CATALAN("ca"),
	/**
	 * 
	 */
	CHINESE("zh"),
	/**
	 * 
	 */
	CHINESE_SIMPLIFIED("zh-CN"),
	/**
	 * 
	 */
	CHINESE_TRADITIONAL("zh-TW"),
	/**
	 * 
	 */
	CROATIAN("hr"),
	/**
	 * 
	 */
	CZECH("cs"),
	/**
	 * 
	 */
	DANISH("da"),
	/**
	 * 
	 */
	/**
	 * 
	 */
	DUTCH("nl"),
	/**
	 * 
	 */
	ENGLISH("en"),
	/**
	 * 
	 */
	FILIPINO("tl"),
	/**
	 * 
	 */
	FINNISH("fi"),
	/**
	 * 
	 */
	FRENCH("fr"),
	/**
	 * 
	 */
	GALACIAN("gl"),
	/**
	 * 
	 */
	GERMAN("de"),
	/**
	 * 
	 */
	GREEK("el"),
	/**
	 * 
	 */
	HEBREW("iw"),
	/**
	 * 
	 */
	HINDI("hi"),
	/**
	 * 
	 */
	HUNGARIAN("hu"),
	/**
	 * 
	 */
	INDONESIAN("id"),
	/**
	 * 
	 */
	ITALIAN("it"),
	/**
	 * 
	 */
	JAPANESE("ja"),
	/**
	 * 
	 */
	KOREAN("ko"),
	/**
	 * 
	 */
	LATVIAN("lv"),
	/**
	 * 
	 */
	LITHUANIAN("lt"),
	/**
	 * 
	 */
	MALTESE("mt"),
	/**
	 * 
	 */
	NORWEGIAN("no"),
	/**
	 * 
	 */
	POLISH("pl"),
	/**
	 * 
	 */
	PORTUGESE("pt"),
	/**
	 * 
	 */
	ROMANIAN("ro"),
	/**
	 * 
	 */
	RUSSIAN("ru"),
	/**
	 * 
	 */
	SERBIAN("sr"),
	/**
	 * 
	 */
	SLOVAK("sk"),
	/**
	 * 
	 */
	SLOVENIAN("sl"),
	/**
	 * 
	 */
	SPANISH("es"),
	/**
	 * 
	 */
	SWEDISH("sv"),
	/**
	 * 
	 */
	THAI("th"),
	/**
	 * 
	 */
	TURKISH("tr"),
	/**
	 * 
	 */
	UKRANIAN("uk"),
	/**
	 * 
	 */
	VIETNAMESE("vi");

	/**
	 * 
	 */
	private final String langName;

	/**
	 * @param sLangName
	 *            language code
	 */
	private GoogleLanguage(final String sLangName) {
		langName = sLangName;
	}

	/**
	 * @see java.lang.Enum#toString()
	 * @return language code
	 */
	@Override
	public String toString() {
		return langName;
	}

	/**
	 * Check does Google Translate support language <samp>langName</samp>.
	 * 
	 * @see pl.koziolekweb.translator.engine.Language#isAvaliable(java.lang.String)
	 * 
	 * @param sLangName
	 *            language code
	 * @return true if translator support this language
	 */
	public boolean isAvaliable(final String sLangName) {
		if (sLangName == null || sLangName.trim().length() == 0) {
			return false;
		}
		for (GoogleLanguage gl : values()) {
			if (sLangName.equals(gl.toString())) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Return Google language that has {@link #langName} like param.
	 * @param sLangName language name.
	 * @return Language.
	 */
	public static GoogleLanguage getLangualge(final String sLangName){
		if (sLangName == null || sLangName.trim().length() == 0) {
			return null;
		}
		for (GoogleLanguage gl : values()) {
			if (sLangName.equals(gl.toString())) {
				return gl;
			}
		}
		return null;
	}
}
